import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ViewEngine {
    public static void main1(String[] args) {
        String line = "404  not found ${name}";
        Pattern pattern = Pattern.compile("\\$\\{[^\\}]+\\}", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(line);
        while (matcher.find()){
            String paramName = matcher.group();
            paramName = paramName.replaceAll("\\$\\{|\\}","");
            Object paramValue ="张三";
            if (null == paramValue){
                continue;
            }
            line = matcher.replaceFirst(makeStringForRegexExp(paramValue.toString()));
            matcher = pattern.matcher(line);

        }
        System.out.println(line);

    }
    //处理特殊字符
    public static String makeStringForRegexExp(String str){
        return str.replace("\\","\\\\")
                .replace("*","\\*");
    }

    public static void main(String[] args) {
        testPattern();
    }

    public static void testPattern(){
        Pattern compile = Pattern.compile("public .* com\\.song\\.demo\\.webmvc\\.practice\\.service\\..*Service.*\\(.*\\)");
        Matcher matcher = compile.matcher("public java.lang.String com.song.demo.webmvc.practice.service.impl.QueryServiceImpl.query(java.lang.String)");
        System.out.println(matcher.matches());

        Pattern compile2 = Pattern.compile(".*Service\\..*\\(.*\\)");
        Matcher matcher2 = compile2.matcher("QueryServiceImpl.query(java.lang.String)");
        System.out.println(matcher2.matches());

    }
}
